package pers.cj.pdos.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import pers.cj.pdos.entity.Goods;
import pers.cj.pdos.entity.PacketGoods;
import pers.cj.pdos.mapper.PacketGoodsMapper;
import pers.cj.pdos.service.IPacketGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pers.cj.pdos.vo.CountVo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenj
 * @since 2019-11-04
 */
@Service
public class PacketGoodsServiceImpl extends ServiceImpl<PacketGoodsMapper, PacketGoods> implements IPacketGoodsService {
    @Autowired
    PacketGoodsMapper packetGoodsMapper;
    @Override
    public Map<String, Long> checkByGoodsList(List<Goods> goodsList) {
        List<CountVo> countVoList = packetGoodsMapper.checkByGoodsList(goodsList);
        Map<String,Long> map = new HashMap<>();
        for (CountVo countVo : countVoList) {
            if (!countVo.getId().equals("0") ) {
                Long count = map.get(countVo.getId())==null ? Long.valueOf(0) : map.get(countVo.getId());
                count += countVo.getCount();
                map.put(countVo.getId(), count);
            }
        }
        return map;
    }

    @Override
    public List<PacketGoods> listByListPacket(List list) {
        return packetGoodsMapper.listByListPacket(list);
    }
}
